home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1980-05-17 | 1.5 KB | 32 lines |
- '*********************Err...I can't think of a Title.....*********************
- Rem Although the loops we have shown are very useful and often essential,you
- Rem can't always rely on them in more complex programs.For a more detailed
- Rem explanation of subroutines,look at the on disk document files.
- Rem Where would you need to use a subroutine?Well,imagine that in a game you
- Rem had made,you had a main program loop,and had some `special things for the
- Rem computer to do when the player had won-But you couldn't include these in
- Rem the main bit because you only want them to occur at certain points.
- Rem In this simple program,we start in the MAIN subroutine-It prints some
- Rem text,waits for point 30 of a second and then goes to the subroutine
- Rem SUBBIT(That is where the "Gosub" command comes from-the words GO to a
- Rem SUBroutine)-This prints some text,waits for point ten of a second and
- Rem goes back to where the program left off with the "Return" command-
- Rem which puts us at the line "Gosub MAIN",so we go to the start of the MAIN
- Rem subroutine and start again.
- Rem When you use the Gosub command you write:
- Rem Gosub
- Rem And then the name of the subroutine you want to goto(Here we use MAIN):
- Rem Gosub MAIN
- Rem The start of a subroutine is signalled by its name and a colon after it:
- Rem MAIN:
- Rem don't put anything after the colon,you have to start on the next line
- Rem down.
- MAIN:
- Print "The Main routine!"
- Wait 30
- Gosub SUBBIT
- Gosub MAIN
- SUBBIT:
- Print "The subroutine"
- Wait 10
- Return